package com.kingsoft.dc.khaos.plugin.core

import org.apache.spark.{SparkConf}
import org.apache.spark.sql.{SparkSession}

/**
  * Created by JIANGXIN on 1/3/20.
  */
object ScriptSparkSqlPluginSubmit {

  def main(args: Array[String]) {
    val sqls = args(0).trim
    val config = new SparkConf()
    //    if (isLocal == "true") {
    //      config.setMaster("local[*]")
    //      config.set("spark.driver.bindAddress", "127.0.0.1")
    //    }
    val spark = SparkSession
      .builder()
      .config("hive.merge.sparkfiles", true)
      .config("hive.merge.smallfiles.avgsize", 16000000)
      .config("hive.merge.size.per.task", 256000000)
      .config("hive.exec.dynamic.partition.mode", "nonstrict")
      .config(config)
      .enableHiveSupport()
      .getOrCreate()
    try {
      import spark.sql
      spark.sql(sqls)
    } finally {
      spark.stop()
    }
  }
}
